package com.leilei.sensitive;

import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @author lei
 * @create 2024-05-20 10:23
 * @desc 数据脱敏注解
 **/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
// 加上此注解,会被jackson识别,然后会序列化,如何序列化则看下边JsonSerialize指定的类
@JacksonAnnotationsInside
@JsonSerialize(using = SensitiveJsonSerializer.class)
public @interface Sensitive {

    /**
     * 脱敏数据类型
     */
    SensitiveReplaceEnum type() default SensitiveReplaceEnum.CUSTOMER;

    /**
     * 前置不需要打码的长度,仅脱敏为自定义时有意义
     */
    int prefix() default 0;

    /**
     * 后置不需要打码的长度,仅脱敏为自定义时有意义
     */
    int suffix() default 0;

    /**
     * 脱敏填充符
     */
    String maskStr() default "*";

}
